#include <iostream>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <functional>
//#include <boost/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/shared_ptr.hpp>

using namespace std;
using namespace boost::lambda;

void test1()
{
        string s1();
	cout<<s1<<endl;
        string s2("abcdefghijklmnopqrstuvwxyz");
	cout<<"SIZE:"<<s2.size()<<endl;
	string s3(99,'H');
	cout<<s3<<endl;
//	string s4('H');
	string s4("H");

	string s5(s2,25);
	cout<<s5<<endl;

	string s6(s2,2,4);
	cout<<s6<<endl;

	string s7(s2.begin(),s2.end());
	cout<<s7<<endl;

	string ss[] = {"A","B","C","D","E","F","G","H"}; 
	cout<<"ARRAY SIZE:"<<sizeof(ss)/sizeof(ss[0])<<endl;

}

void SubStr()
{
        string s("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	cout<<s.substr()<<endl;
	cout<<s.substr(0)<<endl;
	cout<<s.substr(0,3)<<endl;
	cout<<s.substr(13,9)<<endl;
	cout<<s.substr(s.find("HI"),9)<<endl;
	//cout<<s.substr(s.find("SIII"),9)<<endl;
	cout<<s.substr(s.find("I"),9)<<endl;
	cout<<s.substr(s.find("I"),s.find("X")-s.find("I")+1)<<endl;
	string::size_type pos1,pos2;
	pos1 = s.find("C");
	pos2 = s.find("S");
	cout<<s.substr(pos1, pos2-pos1+1)<<endl;
	cout<<s.substr(pos1, -9)<<endl;
	cout<<s.substr(2, -1)<<endl;
}

void Misc()
{
        string s("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        string s1("****");

	cout<<boolalpha<<s.empty()<<endl;
	cout<<s.size()<<endl;
	cout<<s.replace(0,3,"OOO")<<endl;
	cout<<s.replace(0,string::npos,"OOO")<<endl;
	cout<<s.replace(0,99,"OOO")<<endl;
	s.swap(s1);
	cout<<s<<endl;
	s.swap(s1);
        s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	cout<<*s.begin()<<endl;
	cout<<*--s.end()<<endl;
	cout<<*----s.end()<<endl;
	cout<<s.data()<<endl;
	cout<<s.c_str()<<endl;
	s.push_back('X');
	s.append("X");
	cout<<s<<endl;
	s.insert(1,"III");
	cout<<s<<endl;
	s.insert(1,"III");
	cout<<s<<endl;
	s.erase(1,6);
	cout<<s<<endl;
}

void Algo()
{
     string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     char buf[100];
     s.copy(buf,100);
     //cout<<buf<<endl;
     copy(s.rbegin(),s.rend(),ostream_iterator<char>(cout));
     cout<<endl;
     copy(s.begin(),s.end(),ostream_iterator<char>(cout));
     cout<<endl;
}

void Npos()
{
     string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     string::size_type pos =  s.find("QQ");
     if(pos == string::npos)
     {
     	     cout<<pos<<endl<<"Not Found"<<endl;
     }
}

void Replace()
{
     string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     string s1 = "abcdefghijklmnopqrstuvwxyz";

     string s2 = s;
     s2.replace(0,3,23,'S');
     s2 = s;
     s2.replace(0,2,4,6);
     cout<<s2<<endl;
     s2.insert(0,3,'8');
     cout<<s2<<endl;
}

void Getline()
{
        string s;
	getline(cin,s);
	cout<<s<<endl;

	getline(cin,s,':');
	cout<<s<<endl;
}

const char* jstrcpy(char* des, const char* src)
{
	char *p = des;
	while(*des++ = *src++);
	return p;
}

const char* jstrcat(char *des, const char *src)
{
	char *p = des;
	while(*des++);
	--des;
	while(*des++ = *src++);
	return p;
}

void C_str()
{
	const size_t size=100;
	char a[size], b[size];
        cout<<jstrcpy(a,"Hello,World!")<<endl;
        cout<<jstrcat(a," I am Junix.")<<endl;
}

int main(int atrgc, char** argv)
{

//      SubStr();
//      Misc();
//	Algo();
//      Npos();
//	Replace();
        C_str();
	/*
	vector<int> V(10);
	generate(V.begin(),V.end(),rand);
	transform(V.begin(), V.end(), V.begin(), _1+1);
	copy(V.begin(),V.end(),ostream_iterator<int>(cout," "));
	cout<<endl;
        */

	return 0;
}
